
#include "relieve.h"
#include "superficie.h"
#include "generador.h"

Relieve::Relieve(Generador &ruidoOffset, Superficie &base,
            float scaleX, float scaleY,
            float dx, float dy) :
   ruidoOffset(ruidoOffset),
   base(base),
   scaleX(scaleX),
   scaleY(scaleY),
   dx(dx),
   dy(dy) {
      }

Coord Relieve::operator()(float u, float v) const {
   return base(u, v);
  /* float x = u * scaleX;
   float y = v * scaleY;

   Coord posicion = base(u, v);
   float z = posicion.z();

   switch(modo) {
      case SUMA:
         posicion.z() = z + ruidoOffset(x, y);
      case MODULACION:
         posicion.z() = z * ruidoOffset(x, y);
      case PASS:
         posicion.z() = z;
      default:
         throw "No!!";
   }

   return posicion;
*/
   }

Coord Relieve::normal(float u, float v) const {
       
   float x = (u*(u - 1.0)) * (scaleX / 0.25);
   float y = (v*(v - 1.0)) * (scaleY / 0.25);

   Coord delta = Coord(0, 0, 
       (ruidoOffset(x + dx, y) - ruidoOffset(x - dx, y)) *
       (ruidoOffset(x, y + dy) - ruidoOffset(x, y - dy)));

   return base.normal(u, v) + delta;
}

Relieve::~Relieve() {
   delete &base;
}
